package com.jackstraw.jack_base.datasource.mybatisplus.base.util;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jackstraw.jack_base.datasource.database.parten.base.entity.page.PageData;
import com.jackstraw.jack_base.datasource.database.parten.base.entity.po.BasePo;
import com.jackstraw.jack_base.util.BeanUtil;

import java.util.List;

/**
 * MyBatisPlus工具类
 */
public final class MyBatisPlusUtil {


    /**
     * 转换page返回数据
     *
     * @param poIPage
     * @param <BO>
     * @param <PO>
     * @return
     */
    public static <BO extends PO, PO extends BasePo<PO>> PageData<BO> pageData(IPage<PO> poIPage, Class<BO> boClass) {
        //当前分页总页数
        long pages = poIPage.getPages();
        //每页显示条数
        int size = (int) poIPage.getSize();
        //当前满足条件总行数
        long total = poIPage.getTotal();
        //当前页
        int current = (int) poIPage.getCurrent();
        //分页记录列表
        List<PO> poList = poIPage.getRecords();

        List<BO> boList =   BeanUtil.copyListProperties(poList,boClass);

        return new PageData<>(total, size, current, boList);
    }

}
